package com.nian.trancation.tc.b.service;

import com.codingapi.txlcn.tc.annotation.DTXPropagation;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.codingapi.txlcn.tc.annotation.TccTransaction;
import com.codingapi.txlcn.tc.annotation.TxcTransaction;
import com.nian.trancation.tc.b.dao.TableTestBRepsitory;
import com.nian.trancation.tc.b.model.TableTestB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.UUID;

/**
 * 用途：
 * 开发：zhangmj
 * 日期：2020/4/15 0015 12:28
 */
@Service
public class TableTestBService {

    @Autowired
    private TableTestBRepsitory tableTestBRepsitory;

    @TxcTransaction(propagation = DTXPropagation.SUPPORTS)
    @Transactional  //本地事务注解
    public TableTestB save(TableTestB model){
        Date date = new Date();
        if(model.getId() !=null){
            model.setUpdateTime(date);
        }else {
            model.setCreateTime(date);
            model.setUpdateTime(date);
        }
        String id = UUID.randomUUID().toString().replace("-","1");
        System.out.println("id的长度：" + id.length());
        model.setId(id);
        return tableTestBRepsitory.save(model);
    }

    @TccTransaction(propagation = DTXPropagation.SUPPORTS)
    @Transactional  //本地事务注解
    public void delete(TableTestB model){
        tableTestBRepsitory.delete(model);
    }
}
